# -*- coding: utf-8 -*-
"""
@Time ： 2024/5/8 16:01
@Auth ： 李天天
"""
import random
import time

import requests

from Common.basepage import BasePage
from Common.connect_to_device import d_one_device
from Common.handle_redis import RedisHelper
# from Common.handle_redis import RedisHelper
from PageObjects.Main_page import MainPage
from PageObjects.Player_page import PlayerPage

do_redis = RedisHelper(host="10.10.118.92", port="6379", password="li123456")


def start_invite():
    BasePage("d_one").start_middleware_app()
    time.sleep(2)
    MainPage("d_one").click_share()
    # time.sleep(2)
    # MainPage("d_one").click_share2()
    time.sleep(2)
    MainPage("d_one").click_slave_invite()
    time.sleep(2)
    MainPage("d_one").click_ok()
    time.sleep(2)
    MainPage("d_one").click_ok_after()
    time.sleep(2)
    MainPage("d_one").click_point(2034, 735, img_desc="点击昨日青空")
    # MainPage("d_one").click_continue_ok()


def watch_movie():
    d_one_device.shell(
        "am start -a android.intent.action.VIEW -d http://10.10.106.44:8054/demo/%E6%98%A8%E6%97%A5%E9%9D%92%E7%A9%BA.mp4")


def finish_share():
    # BasePage("d_one").start_middleware_app()
    # time.sleep(2)
    # MainPage("d_one").click_finish_share()
    MainPage("d_one").click_back()


def press_invite():
    while True:
        start_invite()
        time.sleep(8)
        # watch_movie()
        finish_share()
        time.sleep(2)


if __name__ == '__main__':
    # do_redis.set(key="stop_HQ", value="False", ex="86400")
    # while True:
    #     if not eval(do_redis.get(key="stop_HQ")):
    #         try:
    #             press_invite()
    #         except:
    #             BasePage("d_one").press_key("back")
    #             time.sleep(1)
    #             BasePage("d_one").press_key("back")
    #             # BasePage("d_one").click_point(0.08, 0.509, "点击空白处返回")
    #             # back_to_main()
    #             # requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/多屏1.0自动操作脚本可能出现问题")
    #     else:
    #         break
    # while True:
    #     try:
    #         press_invite()
    #     except:
    #         BasePage("d_one").press_key("back")
    #         time.sleep(1)
    #         # BasePage("d_one").press_key("back")

    # do_redis.set(key="stop_DP_mirror", value="False", ex="86400")
    while True:
        try:
            press_invite()
        except:
            try:
                # requests.get(url="https://api.day.app/s3KoLFVvWVWdYiiro2gKW/CX1E自动操作脚本可能出现问题")
                BasePage("d_one").press_key("back")
                time.sleep(1)
                # BasePage("d_one").press_key("back")
            except:
                pass
